home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 January / enter-2004-01.iso / files / maxima-5.9.0.exe / {app} / share / maxima / 5.9.0 / demo / subscr.dem < prev    next >
Encoding:
Text File  |  2003-02-09  |  1.1 KB  |  26 lines

  1. /* file: subscr.dem   */
  2. /* indices problem    */
  3. /* This file demonstates the subscript mapping capability in MACSYMA which */
  4. /* useful for manipulating matrices, arrays, and arbitrary dimension and   */
  5. /* order data objects constructed as lists of lists of lists...            */
  6.  
  7. SUBSCRMAP:TRUE                /* This enables subscript mapping */;
  8. a[[x1,x2],[y1,y2]]            /* Map a[x,x] over the subscripts */;
  9. m:matrix([a,b],[c,d])            /* enter a matrix */;
  10. M[[1,1,1],[[1,1],[2,2]]]        /* Create a new structure from M */;
  11. af[i,j]:=x^(i+j)            /* Define a generating function */;
  12. iota(n):=                /* index list generator like APL */
  13.     block([l], l:[],
  14.           for i:1 thru n do l:endcons(i,l),
  15.       l)$
  16. il:iota(8)                /* generate an index vector 8 long */;
  17. af[il,il],eval                /* Construct a structure */;
  18. apply(matrix,%)                /* make it a matrix */;
  19. m[[2,1]],eval;
  20. apply(matrix,%);
  21. m[2]                    /* select a row */;
  22. matrix(m[[1,2],[1]]),eval        /* select a column */;
  23. matrix(m[[2,1],''(iota(length(m[1])))]),eval /* select all of one dimension */;
  24. a['[1,2]]                /* use a list as a hashed ary subscript*/;
  25. ARR[[1,2,3,4]]::0.0            /* Assignment.  Note use of ::      */;
  26.